<?php

/**
* Wurfl.class.php
*
* Wurls class
*
* @author     Blazej Zieba <b@zieba.info>
* @copyright  2007 konekto.com
* @version    CVS: $Id:$
*/

require_once 'WURFL/Application.php';

class Wurfl 
{

        private static $requestingDevice = null;
        
        static function deviceFactory()
        {
        
            if ( !isSet (Wurfl::$requestingDevice)  ) 
            {
                $options = &PEAR::getStaticProperty('CONFIG_INI','WURFL');

                $wurflConfig = new WURFL_Configuration_XmlConfig($options['config_file']);
                $wurflManagerFactory = new WURFL_WURFLManagerFactory($wurflConfig);
                $wurflManager = $wurflManagerFactory->create();	 

                Wurfl::$requestingDevice = $wurflManager->getDeviceForHttpRequest($_SERVER);

                if( Wurfl::$requestingDevice->getCapability("is_transcoder") == 'true')
                {
                    $header = Wurfl::$requestingDevice->getCapability("transcoder_ua_header");
                    $header = str_replace("-","_",$header);
                    Wurfl::$requestingDevice = $wurflManager->getDeviceForUserAgent($_SERVER['HTTP_'.strtoupper($header)]);
                }
            }
            return Wurfl::$requestingDevice;

        }

        static function unSetDevice()
        {
            Wurfl::$requestingDevice = null;
        }

        static function getHeight()
        {
            if ( Wurfl::deviceFactory()->getCapability("is_wireless_device") == "true")
            {
                return Wurfl::deviceFactory()->getCapability("max_image_height");
            }
            else
            {
                return 480;
            }
        }

        static function getWidth()
        {
            if ( Wurfl::deviceFactory()->getCapability("is_wireless_device")  == "true" )
            {
                return Wurfl::deviceFactory()->getCapability("max_image_width");
            }
            else
            {
                return 300;
            }
        }
                
        static function isTouchscreen()
        {
            if ( Wurfl::deviceFactory()->getCapability("pointing_method")  == "touchscreen" )
            {
                return true;
            }
            else
            {
                return false;
            }
            
        }

        static function isWireless()
        {
            if ( Wurfl::deviceFactory()->getCapability("is_wireless_device")  == "true" )
            {
                return true;
            }
            else
            {
                return false;
            }
            
        }        
} 
